package com.mc2.docapp.disabilityassessmenttool.UpperLimb;

import io.realm.RealmObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class C_ulmp_wrist extends RealmObject {
    private CustDataType dorsiflexion= new CustDataType();
    private CustDataType palmarflexion= new CustDataType();
    private CustDataType radial_deviation= new CustDataType();
    private CustDataType palmar_deviation= new CustDataType();
    private InnerCalculations inner_calculations = new InnerCalculations();

    public void calc(C_ulmp_wrist c_ulmp_wrist) {
        //RIGHT
        double a = c_ulmp_wrist.getDorsiflexion().getActual_right();
        double b = c_ulmp_wrist.getPalmarflexion().getActual_right();
        double c = c_ulmp_wrist.getRadial_deviation().getActual_right();
        double d = c_ulmp_wrist.getPalmar_deviation().getActual_right();


        double pa = perc(a, c_ulmp_wrist.getDorsiflexion().getNormal());
        double pb = perc(b, c_ulmp_wrist.getPalmarflexion().getNormal());
        double pc = perc(c, c_ulmp_wrist.getRadial_deviation().getNormal());
        double pd = perc(d, c_ulmp_wrist.getPalmar_deviation().getNormal());

        double x = (pa + pb + pc + pd) / 4.0;
        c_ulmp_wrist.getDorsiflexion().setPerc_loss_right(pa);
        c_ulmp_wrist.getPalmarflexion().setPerc_loss_right(pb);
        c_ulmp_wrist.getRadial_deviation().setPerc_loss_right(pb);
        c_ulmp_wrist.getPalmar_deviation().setPerc_loss_right(pb);


        //LEFT
        a = c_ulmp_wrist.getDorsiflexion().getActual_left();
        b = c_ulmp_wrist.getPalmarflexion().getActual_left();
        c = c_ulmp_wrist.getRadial_deviation().getActual_left();
        d = c_ulmp_wrist.getPalmar_deviation().getActual_left();

        pa = perc(a, c_ulmp_wrist.getDorsiflexion().getNormal());
        pb = perc(b, c_ulmp_wrist.getPalmarflexion().getNormal());
        pc = perc(c, c_ulmp_wrist.getRadial_deviation().getNormal());
        pd = perc(d, c_ulmp_wrist.getPalmar_deviation().getNormal());
        double y = (pa + pb + pc + pd) / 4.0;

        c_ulmp_wrist.getDorsiflexion().setPerc_loss_left(pa);
        c_ulmp_wrist.getPalmarflexion().setPerc_loss_left(pb);
        c_ulmp_wrist.getRadial_deviation().setPerc_loss_left(pb);
        c_ulmp_wrist.getPalmar_deviation().setPerc_loss_left(pb);

        c_ulmp_wrist.setInner_calculations(new InnerCalculations(
                x,
                y,
                x * 0.3,
                y * 0.3
        ));
    }

    private double perc(double a, double normal) {
        return ((normal - a) * 100d) / (normal + 0d);
    }

}
